package timerservice;
import java.util.TimerTask;
import java.util.Timer;
import java.util.Date;
//import com.siwei.util.IDCodeUtil;
/**
 *
 * */
abstract public class SwTimerTask extends TimerTask{
  long period=-1;//循环调用时间,为-1时无循环调用
  Date firstDate=null;//第一次执行时间
  long delay=0;//延迟执行时间（若有firstDate则delay无效）
  String taskCode="";
  TimerTaskManager manager=null;
  public SwTimerTask(String _taskCode){
    if(_taskCode==null||_taskCode.trim().equals("")){
       _taskCode=IDCodeUtil.generateUniqueID();
    }
    this.taskCode=_taskCode;
  }
  public String getTaskCode(){
    return taskCode;
  }
  public void setTimerTaskManager(TimerTaskManager manager){
    this.manager=manager;
  }
  public void run(){
    execute();
    manager.deleteTimerTaskByCode(taskCode,false);
    manager=null;
  }
  abstract public void execute();
  public long getPeriod(){
    return period;
  }
  public Date getFirstDate(){
    return firstDate;
  }
  public long getDelay(){
    return delay;
  }
  public void setPeriod(long period){
    this.period=period;
  }
  public void setFirstDate(Date date){
    firstDate=date;
  }
  public void setDelay(long delay){
    this.delay=delay;
  }
}